package com.ia.aistream.service.operating.impl;

import com.ia.aistream.manager.operating.conf.DocMapConf;

import com.ia.aistream.mapper.operating.DocContentTableMapper;
import com.ia.aistream.mapper.operating.DocTitleMapper;
import com.ia.aistream.model.operating.entity.DocContentTable;
import com.ia.aistream.model.operating.entity.DocTitle;
import com.ia.aistream.service.operating.IDocContentTableOrTitleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
@Service
public class DocContentTableOrTitleServiceImpl implements IDocContentTableOrTitleService {
    @Autowired
    private DocTitleMapper docTitleMapper;

    @Autowired
    private DocContentTableMapper docContentTableMapper;

    @Transactional
    @Override
    public int addTableAndTitle(Map<String,Object> map){
        DocTitle title = (DocTitle) map.get(DocMapConf.DOC_TITLE.value);
        List<DocContentTable> list = (List<DocContentTable>) map.get(DocMapConf.DOC_TABLE_LIST.value);
        int id = docTitleMapper.insertDocTitle(title);
        for (DocContentTable d : list) {
            d.setDocTitleId(id+"");
        }
        int result = docContentTableMapper.inserDocContentTableList(list);
        return result;
    }
}
